package com.mx.zb.mng.utils;

import com.mx.zb.mng.utils.context.ContextThread;
import com.mx.zb.mng.utils.db2.Page;

/**
 * 
 * @author Administrator
 *
 */
public class AjaxResult {

	public static final String OK = "1";
	public static final String ERROR = "2";
	public static final String NOLOGIN = "3";
	public static final String EX_ERROR = "4";

	private String status;
	private String message;
	private Object data;
	
	private int draw;
	private long recordsTotal;
	private long recordsFiltered;

	public AjaxResult success() {
		this.status = OK;
		return this;
	}

	public AjaxResult success(Object data) {
		this.status = OK;
		if(data instanceof Page) {
			Page p = (Page)data;
			this.draw = ContextThread.get().getDraw();
			this.recordsTotal = p.getTotal();
			this.recordsFiltered = p.getTotal();
		}
		this.data = data;
		return this;
	}
	
	public AjaxResult noLogin() {
		this.status = NOLOGIN;
		return this;
	}

	public AjaxResult failure() {		
		return failure(null);
	}

	public AjaxResult failure(String message) {
		this.status = ERROR;
		this.message = message;
		return this;
	}
	
	public AjaxResult exception(String message) {
		this.status = EX_ERROR;
		this.message = message;
		return this;
	}
	

	public Object getData() {
		return data;
	}

	public String getStatus() {
		return status;
	}

	public String getMessage() {
		return message;
	}

	public int getDraw() {
		return draw;
	}

	public void setDraw(int draw) {
		this.draw = draw;
	}

	public long getRecordsTotal() {
		return recordsTotal;
	}

	public void setRecordsTotal(long recordsTotal) {
		this.recordsTotal = recordsTotal;
	}

	public long getRecordsFiltered() {
		return recordsFiltered;
	}

	public void setRecordsFiltered(long recordsFiltered) {
		this.recordsFiltered = recordsFiltered;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void setData(Object data) {
		this.data = data;
	}

	

}
